package com.mmall.utils;

import com.mmall.common.ResponseCode;
import com.mmall.common.ServerResponse;
import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.util.Date;

public class DateTimeUtil {

    private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static String dateToStr(Date date) {
        if (date == null) {
            return StringUtils.EMPTY;
        }

        DateTime dateTime = new DateTime(date);
        return dateTime.toString(DATE_FORMAT);
    }

    public static Date strToDate(String dateStr) {
        if (StringUtils.isBlank(dateStr)) {
            return null;
        }
        DateTimeFormatter formatter = DateTimeFormat.forPattern(DATE_FORMAT);
        DateTime dateTime = formatter.parseDateTime(dateStr);
        return null;
    }

    public static String dateToStr(Date date, String formateStr) {
        if (date == null) {
            return StringUtils.EMPTY;
        }

        DateTime dateTime = new DateTime(date);
        return dateTime.toString(formateStr);
    }

    public static Date strToDate(String dateStr, String formateStr) {
        if (StringUtils.isBlank(dateStr)) {
            return null;
        }
        DateTimeFormatter formatter = DateTimeFormat.forPattern(formateStr);
        DateTime dateTime = formatter.parseDateTime(dateStr);
        return null;
    }

}
